import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:BeeApp/ShopPage/UserOrderListPage01.dart';
import 'package:BeeApp/ShopPage/UserOrderListPage02.dart';
import 'package:BeeApp/ShopPage/UserOrderListPage03.dart';
import 'package:flutter/material.dart';

class UserMainPage03 extends StatefulWidget {
  UserMainPage03({Key key}) : super(key: key);

  @override
  UserMainPage03State createState() => UserMainPage03State();
}

class UserMainPage03State extends State<UserMainPage03> {
  TabController _controller;
  List tabs = ["待接单", "待送达", "已完成"];
  List pages = [
    UserOrderListPage01(),
    UserOrderListPage02(),
    UserOrderListPage03()
  ];

  @override
  void initState() {
    super.initState();
    _controller = TabController(
      length: tabs.length,
      vsync: ScrollableState(),
    );

    _controller.addListener(
      () {
        if (_controller.index.toDouble() == _controller.animation.value) {
          //赋值 并更新数据
          this.setState(() {
            print(_controller.index);
            if (_controller.index == 0) {
              print("全部订单");
            } else if (_controller.index == 1) {
              print("已处理订单");
            } else {
              print("未处理订单");
            }
          });
        }
      },
    );
  }

  @override
  void dispose() {
    super.dispose();
    _controller?.removeListener(() {});
    _controller?.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(40),
        child: Material(
          color: Colors.white,
          child: TabBar(
              indicator: BoxDecoration(
                color: maincolor,
              ),
              labelColor: Colors.white,
              unselectedLabelColor: Color(0xFF999999),
              controller: _controller,
              indicatorSize: TabBarIndicatorSize.tab,
              labelStyle: TextStyle(fontSize: setFontSize(30)),
              //生成Tab菜单
              tabs: tabs.map((e) => Tab(text: e)).toList()),
        ),
      ),
      body: TabBarView(
          controller: _controller,
          // children: pages.map((e) {
          //   //分别创建对应的Tab页面
          //   return OrderListPage01();
          // }).toList(),
          children: pages.map((e) => Tab(child: e)).toList()),
    );
  }
}
